import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class serialObj implements Serializable {
    private int age;
    private  String name;

    public serialObj(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "serialObj{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    public static void main(String[] args) throws IOException {
        FileOutputStream outputStream=new FileOutputStream("C:\\Users\\22453\\Desktop\\test.txt");
        ObjectOutputStream outputStream1=new ObjectOutputStream(outputStream);
        List<serialObj>serialObjs=new ArrayList<>();
        for(int i=0;i<10;i++){
            serialObj s=new serialObj(i,"name"+i*i);
            serialObjs.add(s);
            outputStream1.writeObject(s);
        }
        System.out.println(serialObjs);
        outputStream.close();
        outputStream1.close();
        outputStream.close();
    }
}
